﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yipusoft.ProfessionalTeam.DAL;

public partial class MapInfo_ProfessionalTeam_Assault : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindddlType();
            bindList();
        }
    }

    void bindList()
    {
        string DepartmentId = Request["DepartmentId"];
        TeamDataContext tdc = new TeamDataContext();
        List<Assault> list = tdc.Assault.Where(o => o.DepartmentId == DepartmentId).ToList();
        gv.DataSource = list;
        gv.DataBind();
        lblDepartment.Text = Yipusoft.Account.BLL.Department.GetDepartment(DepartmentId).ShortName;
    }
    protected void lblReturn_Click(object sender, EventArgs e)
    {
        //返回
    }
    protected void butOk_Click(object sender, EventArgs e)
    {
        //保存
        string DepartmentId = Request["DepartmentId"];
        TeamDataContext tdc = new TeamDataContext();
        Assault assult = new Assault();
        assult.DepartmentId = DepartmentId;
        assult.Id = Guid.NewGuid();
        assult.TypeId = Convert.ToInt32(ddlType.SelectedValue);
        tdc.Assault.InsertOnSubmit(assult);
        tdc.SubmitChanges();
        bindList();
    }
    protected void isFlag_CheckedChanged(object sender, EventArgs e)
    {
        BindddlType();
    }

    void BindddlType()
    {
        TeamDataContext tdc = new TeamDataContext();
        int Flag = 0;
        if (isFlag.Checked)
        {
            Flag = 1;
        }
        List<AssaultType> typeList = tdc.AssaultType.Where(o => o.Flag == Flag).ToList();
        ddlType.DataSource = typeList;
        ddlType.DataBind();
    }
    protected void gvSoldiers_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label ID = (Label)e.Row.FindControl("ID");
            ID.Text = (e.Row.RowIndex + 1).ToString();
            //当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色 
            e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#F5F5F5',this.style.fontWeight='';");
            //当鼠标离开的时候 将背景颜色还原的以前的颜色 
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';");
            Assault assault = e.Row.DataItem as Assault;
            TeamDataContext tdc = new TeamDataContext();
            Label lblName = e.Row.FindControl("lblName") as Label;
            Label lblIsStandard = e.Row.FindControl("lblIsStandard") as Label;
            Label lblUpdateDate = e.Row.FindControl("lblUpdateDate") as Label;
            lblName.Text = tdc.AssaultType.Where(o => o.Id == assault.TypeId).FirstOrDefault().TypeName;
            if (Yipusoft.ProfessionalTeam.BLL.Stat.isComplianceAssaultByPid(assault.Id))
            {
                lblIsStandard.Text = "√";
            }
            else
            {
                lblIsStandard.Text = "×";
            }
            lblUpdateDate.Text = Yipusoft.ProfessionalTeam.BLL.Stat.GetAssaultLastUpdateDate(assault.Id) == DateTime.MinValue ? "" : Yipusoft.ProfessionalTeam.BLL.Stat.GetAssaultLastUpdateDate(assault.Id).ToShortDateString();
        }

    }
    protected void gv_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "del")
        {
            Guid id = new Guid(e.CommandArgument.ToString());
            TeamDataContext tdc = new TeamDataContext();
            Assault assault = tdc.Assault.Where(o => o.Id == id).FirstOrDefault();
            tdc.Assault.DeleteOnSubmit(assault);
            tdc.SubmitChanges();
            bindList();
        }
        if (e.CommandName == "SD")
        {
            Response.Redirect(Server.HtmlEncode("HelpNew.aspx?DepartmentId=" + Request["DepartmentId"]) + "" + "&Aid=" + e.CommandArgument + "&Type=2");
        }
    }
}
